package com.bbx.taxi.client.Task;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.AsyncTask;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Offciail_CancelPriceBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Offciail_CancelPrice;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Price;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Offciail_CancelPriceNet;
import com.bbx.api.sdk.net.official.passanger.Officail_PriceNet;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Task.MyOperateTask.OnOperateStatusListener;
import com.bbx.taxi.official.R;

/** 
 * @Path com.bbx.taxi.client.Task.MyPriceTask.java
 * @Author 严旭文
 * @Date 2016-2-18 上午10:12:00
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 获取价格，2中，分别为主界面的获取价格，跟取消订单的消费金额
 */
public class MyCancelPriceTask {
	public static int STATUS_SUCCESS=0;
	public static int STATUS_FAIL=-1;
	private Activity context;
	public CancelPriceTask mCancelPriceTask;
	public static MyCancelPriceTask instance;
	public interface OnCancelPriceListener {
		/**
		 * 获取价格
		 *status 0为成功,
		 */
		public void onCancelPrice(int status,int price);
	}

	static OnCancelPriceListener mOnCancelPriceListener = null;

	public static void setOnCancelPriceListener(OnCancelPriceListener l) {
		mOnCancelPriceListener = l;
	}
	public static MyCancelPriceTask getInstance(Activity context,Offciail_CancelPriceBuild mOffciail_CancelPriceBuild) {
		instance = new MyCancelPriceTask(context,mOffciail_CancelPriceBuild);
		return instance;
	}
	public MyCancelPriceTask(Activity context,Offciail_CancelPriceBuild mOffciail_CancelPriceBuild) {
		this.context = context;
		getPrice(mOffciail_CancelPriceBuild);
	}
	public void getPrice(Offciail_CancelPriceBuild mOffciail_CancelPriceBuild){
		mCancelPriceTask = new CancelPriceTask(context, mOffciail_CancelPriceBuild);
		mCancelPriceTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	/**
	 * 获取价格
	 * 
	 */
	private class CancelPriceTask extends BaseAsyncTask {

		private Offciail_CancelPriceBuild mOffciail_CancelPriceBuild;

		public CancelPriceTask(Activity context, Offciail_CancelPriceBuild mOffciail_CancelPriceBuild) {
			super(context);
			this.mOffciail_CancelPriceBuild = mOffciail_CancelPriceBuild;
		}

		@Override
		public void onSuccess(Object object) {
			if(object!=null){
				Offciail_CancelPrice mOffciail_CancelPrice = (Offciail_CancelPrice) object;
				if(mOffciail_CancelPrice!=null){
					if (mOnCancelPriceListener != null) {
						mOnCancelPriceListener.onCancelPrice(STATUS_SUCCESS,mOffciail_CancelPrice.getCancelPrice());
					}
				}else{
					if (mOnCancelPriceListener != null) {
						mOnCancelPriceListener.onCancelPrice(STATUS_FAIL,0);
					}
				}
			
			}else{
				if (mOnCancelPriceListener != null) {
					mOnCancelPriceListener.onCancelPrice(STATUS_FAIL,0);
				}
			}
	

		}

		@Override
		public void onFailed(int status, String msg) {
			if (mOnCancelPriceListener != null) {
				mOnCancelPriceListener.onCancelPrice(STATUS_FAIL,0);
			}
			
		}
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOffciail_CancelPriceBuild).getJson();
			return new Offciail_CancelPriceNet(context, json);
		}
	}
}
